﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 角色随机动画
/// </summary>
public class CharacterAnimRandom : StateMachineBehaviour
{
    // 切换动画
    private bool changeAnim;

    public override void OnStateEnter(Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex)
    {
        changeAnim = false;
    }

    public override void OnStateUpdate(Animator animator, AnimatorStateInfo StateInfo, int layerIndex)
    {
        if (animator == null)
            return;
        if (changeAnim)
            return;
        if (StateInfo.normalizedTime >= 1f && !changeAnim)
        {
            if (animator.transform.parent.name == "DummyCharacter")
                return;
            if (animator.GetComponentInParent<PassengerAnim>())
            {
                if (animator.GetComponentInParent<PassengerAnim>().currentIndex == 0)
                {
                    changeAnim = true;
                    var str = "Idle_" + Random.Range(1, 5);
                    animator.SetTrigger(str);
                    PassengerManager.Instance.xrayModelAnim.SetTrigger(str);
                }
                else
                {
                    changeAnim = true;
                    animator.SetTrigger("Idle_" + Random.Range(1, 5));
                }
            }
            else
            {
                changeAnim = true;
                animator.SetTrigger("Idle_" + Random.Range(1, 5));
            }
        }
    }
}
